using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VPJTAET
    {
        public DataRow Convert2PJTAET(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryPJTAET(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["PTAMANDANT"] = " ".PadRight(2 ); 
         dwReturn["PTAPROJNR"] = " ".PadRight(5 ); 
         dwReturn["PTAKD"] = " ".PadRight(24 ); 
         dwReturn["PTALFDNR"] = " ".PadRight(4 ); 
         dwReturn["PTAMASSNAHME"] = " ".PadRight(10 ); 
         dwReturn["PTAPROJLEITER"] = " ".PadRight(8 ); 
         dwReturn["PTAVERANTW"] = " ".PadRight(8 ); 
         dwReturn["PTAVERANTWKZ"] = " ".PadRight(1 ); 
         dwReturn["PTASTATUS"] = " ".PadRight(1 ); 
         dwReturn["PTAUNKLARGRD"] = " ".PadRight(2 ); 
         dwReturn["PTAUEBWKENNZ"] = " ".PadRight(1 ); 
         dwReturn["PTAWIEDERV"] = " ".PadRight(0 ); 
         dwReturn["PTATERMIN"] = " ".PadRight(0 ); 
         dwReturn["PTADATUMERL"] = " ".PadRight(0 ); 
         dwReturn["PTAZUSKOSTEN"] = " ".PadRight(0 ); 
         dwReturn["PTAABSAGEGRD"] = " ".PadRight(2 ); 
         dwReturn["PTAABSAGEBEM"] = " ".PadRight(50 ); 
         dwReturn["PTANEUBEN"] = " ".PadRight(8 ); 
         dwReturn["PTANEUDAT"] = " ".PadRight(0 ); 
         dwReturn["PTAAENDBEN"] = " ".PadRight(8 ); 
         dwReturn["PTAAENDDAT"] = " ".PadRight(0 ); 
         dwReturn["PTAAENDZL"] = " ".PadRight(0 ); 
         dwReturn["PTAFILLER"] = " ".PadRight(40 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapPJTAET(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SavePJTAET(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryPJTAET(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapPJTAET(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertPJTAET(dwLocal, ITXDBVERSION);
            }
            UpdatePJTAET(dwLocal);
        }
        public void InsertPJTAET(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO PJTAET(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryPJTAET(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM PJTAET WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM PJTAET  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "PJTAET";
            Return = Result;
            return Return;
        }
        public void DeletePJTAET(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM PJTAET   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdatePJTAET(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE PJTAET SET "
                    +"PTAMANDANT= :PTAMANDANT,"
                    +"PTAPROJNR= :PTAPROJNR,"
                    +"PTAKD= :PTAKD,"
                    +"PTALFDNR= :PTALFDNR,"
                    +"PTAMASSNAHME= :PTAMASSNAHME,"
                    +"PTAPROJLEITER= :PTAPROJLEITER,"
                    +"PTAVERANTW= :PTAVERANTW,"
                    +"PTAVERANTWKZ= :PTAVERANTWKZ,"
                    +"PTASTATUS= :PTASTATUS,"
                    +"PTAUNKLARGRD= :PTAUNKLARGRD,"
                    +"PTAUEBWKENNZ= :PTAUEBWKENNZ,"
                    +"PTAWIEDERV= :PTAWIEDERV,"
                    +"PTATERMIN= :PTATERMIN,"
                    +"PTADATUMERL= :PTADATUMERL,"
                    +"PTAZUSKOSTEN= :PTAZUSKOSTEN,"
                    +"PTAABSAGEGRD= :PTAABSAGEGRD,"
                    +"PTAABSAGEBEM= :PTAABSAGEBEM,"
                    +"PTANEUBEN= :PTANEUBEN,"
                    +"PTANEUDAT= :PTANEUDAT,"
                    +"PTAAENDBEN= :PTAAENDBEN,"
                    +"PTAAENDDAT= :PTAAENDDAT,"
                    +"PTAAENDZL= :PTAAENDZL,"
                    +"PTAFILLER= :PTAFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("PTAMANDANT", OracleType.NVarChar).Value = dwData["PTAMANDANT"].ToString(); 
          or1.Parameters.Add("PTAPROJNR", OracleType.NVarChar).Value = dwData["PTAPROJNR"].ToString(); 
          or1.Parameters.Add("PTAKD", OracleType.NVarChar).Value = dwData["PTAKD"].ToString(); 
          or1.Parameters.Add("PTALFDNR", OracleType.NVarChar).Value = dwData["PTALFDNR"].ToString(); 
          or1.Parameters.Add("PTAMASSNAHME", OracleType.NVarChar).Value = dwData["PTAMASSNAHME"].ToString(); 
          or1.Parameters.Add("PTAPROJLEITER", OracleType.NVarChar).Value = dwData["PTAPROJLEITER"].ToString(); 
          or1.Parameters.Add("PTAVERANTW", OracleType.NVarChar).Value = dwData["PTAVERANTW"].ToString(); 
          or1.Parameters.Add("PTAVERANTWKZ", OracleType.NVarChar).Value = dwData["PTAVERANTWKZ"].ToString(); 
          or1.Parameters.Add("PTASTATUS", OracleType.NVarChar).Value = dwData["PTASTATUS"].ToString(); 
          or1.Parameters.Add("PTAUNKLARGRD", OracleType.NVarChar).Value = dwData["PTAUNKLARGRD"].ToString(); 
          or1.Parameters.Add("PTAUEBWKENNZ", OracleType.NVarChar).Value = dwData["PTAUEBWKENNZ"].ToString(); 
          or1.Parameters.Add("PTAWIEDERV", OracleType.NVarChar).Value = dwData["PTAWIEDERV"].ToString(); 
          or1.Parameters.Add("PTATERMIN", OracleType.NVarChar).Value = dwData["PTATERMIN"].ToString(); 
          or1.Parameters.Add("PTADATUMERL", OracleType.NVarChar).Value = dwData["PTADATUMERL"].ToString(); 
          or1.Parameters.Add("PTAZUSKOSTEN", OracleType.NVarChar).Value = dwData["PTAZUSKOSTEN"].ToString(); 
          or1.Parameters.Add("PTAABSAGEGRD", OracleType.NVarChar).Value = dwData["PTAABSAGEGRD"].ToString(); 
          or1.Parameters.Add("PTAABSAGEBEM", OracleType.NVarChar).Value = dwData["PTAABSAGEBEM"].ToString(); 
          or1.Parameters.Add("PTANEUBEN", OracleType.NVarChar).Value = dwData["PTANEUBEN"].ToString(); 
          or1.Parameters.Add("PTANEUDAT", OracleType.NVarChar).Value = dwData["PTANEUDAT"].ToString(); 
          or1.Parameters.Add("PTAAENDBEN", OracleType.NVarChar).Value = dwData["PTAAENDBEN"].ToString(); 
          or1.Parameters.Add("PTAAENDDAT", OracleType.NVarChar).Value = dwData["PTAAENDDAT"].ToString(); 
          or1.Parameters.Add("PTAAENDZL", OracleType.NVarChar).Value = dwData["PTAAENDZL"].ToString(); 
          or1.Parameters.Add("PTAFILLER", OracleType.NVarChar).Value = dwData["PTAFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
